<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/common/taglib.jsp"%>
<!DOCTYPE html>
<html>
<head>
<%@ include file="/WEB-INF/common/head.jsp"%>
</head>
<body class="${cookie.bodyClass.value}">
	<div class="container body">
		<div class="main_container">
			<%@ include file="/WEB-INF/common/left.jsp"%>
			<%@ include file="/WEB-INF/common/top.jsp"%>
			<!-- page content -->
			<div class="right_col" role="main" id="main">
				<div class="x_panel">
					<div class="x_title">
						<h2>控制APP审核列表</h2>
						<div class="clearfix"></div>
					</div>
					<div class="x_content">
						<form role="form" id="searchForm">
							<div class="container">
								<div class="row">
									<div class="col-lg-3">
										<button type="button" class="btn btn-success btn-sm" onclick="add();">新增</button>
									</div>
								</div>
							</div>
						</form>
						<div class="table-responsive">
							<table id="controlAudits" class="table table-bordered table-striped table-hover" 
							  cellspacing="0" width="100%">
								<thead>
									<tr class="mytableHead">
										<th class="myRowNumber"></th>
										<th>版本</th>
										<th>类型</th>
										<th>是否审核</th>
										<th>操作</th>
									</tr>
								</thead>
							</table>
						</div>
					</div>
				</div>
			</div>
			<!-- /page content -->
			<%@ include file="/WEB-INF/common/foot.jsp"%>
		</div>
	</div>
	<%@ include file="/WEB-INF/common/script.jsp"%>
	<script>
	$(function(){
		var t = $("#controlAudits").DataTable({
		    ajax: {
		        url: ctx+'admin/controlAudit/findControlAudits',
		        type: 'POST'
		    },
		    columns: [
		        { "data":null,"render":rowNumberRender},
                { "data":'version'},    
                { "data":'type',"render":typeRender},    
                { "data":'isAudit',"render":isAuditRender},    
		        { "data":'id',"render":optRender}
		    ]
		});
	});
	function optRender(data, type, row, meta){
		var but = '';
		but = but +  '<a class="btn btn-info btn-xs" href="javascript:view('+meta.row+')"><i class="fa fa-pencil"></i>编辑</a>';
		but = but + '<a class="btn btn-danger btn-xs" href="javascript:deleteById('+row.controlAuditId+')"><i class="fa fa-remove"></i>删除</a>'; 
		return but;
	}
	function add(){
		window.location = ctx+"admin/controlAudit/toControlAuditDetailPage";
	} 
	function view(index,event){
		var row = $('#controlAudits').DataTable().rows().data()[index];
		window.location = ctx+"admin/controlAudit/toControlAuditDetailPage?controlAuditId="+row.controlAuditId;
	}
	function typeRender(data, type, row, meta){
		var type = row.type;
		if(Number(type)==0){
		    return 'iOS';
		}else if(Number(type)==1){
            return '安卓';
		}
	}
	function isAuditRender(data, type, row, meta){
		var  isAudit = row. isAudit;
		if(Number(isAudit)==0){
		    return '未审核';
		}else if(Number(isAudit)==1){
            return '审核通过';
		}
	}
	function search(){
		$('#controlAudits').DataTable().ajax.reload();
	}
	function isAudit(isAudit,controlAuditId){
		var text=null;
		if (isAudit==0) {
			text="确定该条记录未审核";
		}
		if (isAudit==1) {
			text="确定该条记录审核通过";
		}
		swal({ "title": "", "text":  text ,"type": "warning","showCancelButton":true},function(isConfirm){
			if(isConfirm){
				$.ajax({
					url: ctx+"admin/controlAudit/isAudit?time="+(new Date()).getTime(),
					dataType: "json",
					data:{
						isAudit:isAudit,
						controlAuditId:controlAuditId
					},
					success: function(result){
						if(result.status == "0"){
							search();
						}else{
							swal({title:'',text:result.msg,type:"error"});
						}
					}
				});
			}
		});
	}
	function deleteById(id){
		swal({ "title": "", "text": "确定要删除该条记录" ,"type": "warning","showCancelButton":true},function(isConfirm){
			if(isConfirm){
				$.ajax({
					url: ctx+"admin/controlAudit/deleteControlAudit?controlAuditId="+id+"&time="+(new Date()).getTime(),
					dataType: "json",
					success: function(result){
						if(result.status == "0"){
							search();
						}else{
							swal({title:'',text:result.msg,type:"error"});
						}
					}
				});
			}
		});
	}
	</script>
</body>
</html>